﻿using AuroraPlatform.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AuroraPlatform.View.Level2
{
    public partial class LableItem : UserControl
    {
        public LableItem()
        {
            InitializeComponent();

            Pictures.SelectionChanged += Pictures_SelectionChanged;
        }

        public void Attach()
        {
            Pictures.SelectionChanged += Pictures_SelectionChanged;
        }

        public void Dettach()
        {
            Pictures.SelectionChanged -= Pictures_SelectionChanged;
        }

        public INavigate Navigation
        {
            get;
            set;
        }

        private void Pictures_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LightingClassModel lighting = (LightingClassModel)Pictures.SelectedItem;

            CondProdSeries.Builder builder = new CondProdSeries.Builder();

            NaviTo2Param parameter = (NaviTo2Param)BusinessContext.Singleton.ParamIterator.Current;
            CondProdClass cond = parameter.Parameter;
            if (cond.HasUsePlace)
                builder.SetUsePlace(cond.UsePlace);

            if (cond.HasSetup)
                builder.SetSetup(cond.Setup);

            if (cond.HasClass)
                builder.SetProductClass(cond.Class);

            if (!string.IsNullOrEmpty(lighting.ProdLabel))
                builder.SetLable(lighting.ProdLabel);

            if (!string.IsNullOrEmpty(lighting.ProdSeries))
                builder.SetSeries(lighting.ProdSeries);

            if (lighting.AdpClass > 0)
                builder.SetAdpaterClass(lighting.AdpClass);

            if (!string.IsNullOrEmpty(lighting.PicFacade))
                builder.SetFacade(lighting.PicFacade.Replace(BusinessContext.Singleton.ImageUrl, ""));

            BusinessContext.Singleton.ParamIterator.GoNew(
                new NaviTo3Param() 
                { 
                    Parameter = builder.Build(),
                    CurrentUrl = MainPage.Level3Uri
                    // SourceUrl = MainPage.Level2Uri
                });
            Navigation.Navigate(new Uri(MainPage.Level3Uri, UriKind.RelativeOrAbsolute));
        }
    }
}
